package com.wish.wishsystem_management.service.impl;

import com.wish.wishsystem_management.entity.TbConfigUserBusinessCircle;
import com.wish.wishsystem_management.mapper.TbConfigUserBusinessCircleMapper;
import com.wish.wishsystem_management.service.ITbConfigUserBusinessCircleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户商圈表 服务实现类
 * </p>
 *
 * @author zhaiwj
 * @since 2021-03-22
 */
@Service
public class TbConfigUserBusinessCircleServiceImpl extends ServiceImpl<TbConfigUserBusinessCircleMapper, TbConfigUserBusinessCircle> implements ITbConfigUserBusinessCircleService {

    @Override
    public List<Long> queryBusinessCircleIdList(Long userId) {
        return baseMapper.queryBusinessCircleIdList(userId);
    }

    @Override
    public void saveOrUpdate(Long userId, List<Long> businessCircleIdList) {
        if (CollectionUtils.isEmpty(businessCircleIdList)) {
            baseMapper.delete(userId);
            return;
        }

        //先删除用户与商圈关系
        baseMapper.delete(userId);

        //保存用户与角色关系
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("businessCircleIdList", businessCircleIdList);
        try {
            baseMapper.save(map);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

    }

    @Override
    public void deleteBatch(Long[] userIds) {
        baseMapper.deleteBatch(userIds);
    }
}
